﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>工序期量迭代维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div id="mainDiv">
        <div class="panelSection">
            <div class="easyui-panel " title="查询区域" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px">
                    <div id="productContent">
                    </div>
                    <div id="workflowContent">
                    </div>
                    <div style="float: left; margin-left: 10px;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            分厂：</div>
                        <select style='width: 120px; height: 22px' id='selFactory' data-options="editable:false,panelHeight:'auto'"
                            class='easyui-combobox'>
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            申请状态：</div>
                        <select style='width: 100px; height: 22px' id='selStatus' data-options="value:'0',editable:false,panelHeight:'auto'"
                            class='easyui-combobox'>
                            <option value="0">已创建</option>
                            <option value="1">已提交</option>
                            <option value="2">已审核</option>
                            <option value="3">已退回</option>
                        </select>
                    </div>
                    <div style="float: left; margin-left: 20px">
                        <button id="btnSearch" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                            width: 80px">
                            查询</button>
                        <button id="btnReset" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                            margin-left: 5px; width: 60px">
                            重置</button>
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="工序期量迭代申请" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px">
                    <button id="btnAdd" class="easyui-linkbutton" type="button" style="width: 60px; height: 26px;">
                        添加</button>
                    <button id="btnEdit" class="easyui-linkbutton" type="button" style="width: 60px;
                        height: 26px;">
                        编辑</button>
                    <button id="btnDele" class="easyui-linkbutton" type="button" style="width: 60px;
                        height: 26px;">
                        删除</button>
                    <button id="btnSendAudit" class="easyui-linkbutton" type="button" style="width: 80px;
                        height: 26px;">
                        提交审批</button>
                    <button id="btnSendERP" class="easyui-linkbutton" type="button" style="width: 120px;
                        height: 26px;">
                        发布到ERP</button>
                </div>
                <div style="margin: 3px 0px 3px 3px">
                    <table id="gdWorkflowinfo" class="easyui-datagrid" style="width: 100%; height: 200px"
                        data-options="rownumbers:true,selectOnCheck:false,singleSelect:true">
                    </table>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="工序期量明细预览" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px">
                    <table id="gdSpecInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                        data-options="rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--以下为弹窗页面-->
    <div id="dg" title="编辑工序期量迭代" style="width: 1000px; height: 600px; display: none"
        data-options="iconCls:'icon-save',resizable:true">
        <div class="panelSection">
            <div class="easyui-panel " title="汇总信息" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px">
                    <div id="productContentDialog">
                    </div>
                    <div id="workflowContentDialog">
                    </div>
                    <div style="float: left; margin-left: 10px;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            参考周期：</div>
                        <input id="txtStartDate" type="text" class="easyui-datebox" style="width: 120px;
                            height: 20px" />
                        -
                        <input id="txtEndDate" type="text" class="easyui-datebox" style="width: 120px; height: 20px" />
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
                <div style="margin: 3px 0px 3px 3px">
                    <div style="float: left;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            总工时上限：</div>
                        <input id="txtTotaltimelimit" class="easyui-textbox" style="width: 90px; height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            维护总工时：</div>
                        <input id="txtMaintenanceTotalTime" class="easyui-textbox" style="width: 90px; height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            更新工艺：</div>
                        <select style='width: 180px; height: 22px' id='selRenewWorkflow' data-options="editable:false,panelHeight:'auto'"
                            class='easyui-combobox'>
                        </select>
                    </div>
                    <div style="float: left; margin-left: 20px">
                        <button id="btnRealTime" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                            width: 120px">
                            计算实时工时</button>
                        <button id="btnSave" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                            margin-left: 5px; width: 60px">
                            保存</button>
                    </div>
                    <div style="margin-left: 10px; padding-top: 20px; float: left">
                        <label style="color: Red;">
                            警告：维护总工时超过总工时上限！请检查并修改</label></div>
                    <div style="clear: both">
                    </div>
                </div>
                <div style="margin: 3px 0px 3px 3px">
                    <table id="gdEditStepInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                        data-options="rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ProductLinkageWorkflow.js"
    type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2023-07-17
    描述：工序期量迭代维护js
    */

    /*---------主页面对象-------------*/
    var page = {
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/WorkflowStepAmountIterationHandler.ashx",
        commoUrl: getRootPath() + "/Ashx/CommonHandler.ashx",
        //初始化
        init: function () {
            page.bind();
            dialogPage.bind();
            page.bindPageData();
        },
        //页面事件绑定
        bind: function () {
            //工艺列表加载
            $("#gdWorkflowinfo").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'PRODUCTNAMEANDREV', title: '件号', width: 150 },
                 { field: 'TOTALTIMELIMIT', title: '总工时上限', width: 80 },
                 { field: 'MAINTENANCETOTALTIME', title: '维护总工时', width: 80 },
                 { field: 'REFERWORKFLOWNAMEANDREV', title: '参考工艺版次', width: 180 },
                 { field: 'RENEWWORKFLOWNAMEANDREV', title: '更新工艺版次', width: 180 },
                 { field: 'FACTORYNAME', title: '分厂', width: 80 },
                 { field: 'STATUSNAME', title: '申请状态', width: 60 },
                 { field: 'MODIFYEMPNAME', title: '修改人', width: 60 },
                 { field: 'MODIFYDATE', title: '修改日期', width: 80,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                 { field: 'CREATEEMPNAME', title: '创建人', width: 60 },
                 { field: 'CREATEDATE', title: '创建日期', width: 80,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]],
                onClickRow: function (rowIndex, rowData) {
                    $("#gdWorkflowinfo").datagrid("uncheckAll");
                    $("#gdWorkflowinfo").datagrid("checkRow", rowIndex);
                    page.bindStepInfo(rowData);
                }
            });
            //工序列表加载
            $("#gdSpecInfo").datagrid({
                columns: [[
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'FACTORYNAME', title: '分厂', width: 100 },
                 { field: 'WORKCENTERNAME', title: '工区', width: 80 },
                 { field: 'TEAMNAME', title: '班组', width: 80 },
                 { field: 'SPECTYPE', title: '工序类型', width: 60 },
                 { field: 'NCNUMBERNAME', title: '是否数控序', width: 70 },
                 { field: 'PREPARECYCLE', title: '准备时间(!)', width: 80 },
                 { field: 'PREPARECYCLEEDIT', title: '准备时间(min)', width: 90 },
                 { field: 'CLAMPINGCYCLE', title: '装夹时间(!)', width: 80 },
                 { field: 'MAKECYCLE', title: '加工时间(!)', width: 80 },
                 { field: 'MAKECYCLEEDIT', title: '加工时间(min)', width: 90 },
                 { field: 'TRANSFERCYCLE', title: '运转时间(!)', width: 80 },
                 { field: 'TRANSFERCYCLEEDIT', title: '运转时间(min)', width: 90 },
                 { field: 'SHIPCYCLE', title: '转工周期(!)', width: 80 },
                 { field: 'SHIPCYCLEEDIT', title: '转工周期(h)', width: 80 },
                 { field: 'COMMICYCLE', title: '外委周期(!)', width: 80 },
                 { field: 'COMMICYCLEEDIT', title: '外委周期(d)', width: 80 },
                 { field: 'MAKEEMPCOUNTS', title: '作业人数', width: 70 },
                 { field: 'CHARGINGQTY', title: '装炉量', width: 70 }
                ]]
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.search();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true, true);
            });
            //添加按钮
            $('#btnAdd').on("click", function () {
                page.dialogs();
            });
            //编辑按钮
            $('#btnEdit').on("click", function () {
                var selected = $("#gdWorkflowinfo").datagrid("getChecked");
                if (selected.length === 0) {
                    displayMessage("请选择数据", false);
                    page.enableBtn(); //恢复所有按钮
                    return false;
                }
                if (selected.length > 1) {
                    displayMessage("请选择一条数据进行编辑", false);
                    page.enableBtn(); //恢复所有按钮
                    return false;
                }
                page.dialogs(selected[0]);
            });
            //删除按钮
            $('#btnDele').on("click", function () {
                page.deleData();
            });
            //提交审批按钮
            $('#btnSendAudit').on("click", function () {
                page.sendAudit(1);
            });
            //提交审批按钮
            $('#btnSendERP').on("click", function () {
                page.sendAudit(4);
            });
            //状态下拉事件
            $('#selStatus').combobox({
                onSelect: function (record) {
                    page.clearPage(false, true, true);
                    switch (record.value) {
                        case "0": //已创建
                            $("#btnEdit").show();
                            $("#btnDele").show();
                            $("#btnSendAudit").show();
                            $("#btnSendERP").hide();
                            break;
                        case "1": //已提交
                            $("#btnEdit").hide();
                            $("#btnDele").hide();
                            $("#btnSendAudit").hide();
                            $("#btnSendERP").hide();
                            break;
                        case "2": //已审核
                            $("#btnEdit").hide();
                            $("#btnDele").hide();
                            $("#btnSendAudit").hide();
                            $("#btnSendERP").show();
                            break;
                        case "3": //已退回
                            $("#btnEdit").show();
                            $("#btnDele").show();
                            $("#btnSendAudit").show();
                            $("#btnSendERP").hide();
                            break;
                        default: break;
                    }
                }
            });
        },
        //初始化页面数据
        bindPageData: function () {
            page.post(page.commoUrl, { action: "getFactory" }, true, function (res) {
                //分厂
                $("#selFactory").combobox({
                    valueField: 'FACTORYID',
                    textField: 'FACTORYNAME',
                    data: res, //下拉数据
                    value: res[0].FACTORYID//默认选中第一个
                });
            });
        },
        //查询
        search: function () {
            page.clearPage(false, true, true);
            var param = {
                status: $("#selStatus").combobox("getValue"),
                factoryID: $("#selFactory").combobox("getValue"),
                productID: $("#productContent").productCombo("getValue"),
                workflowID: $("#workflowContent").workflowCombo("getValue")
            };
            var formData = {
                action: "GetWorkflowIterationInfo",
                param: JSON.stringify(param)
            };
            page.post(page.url, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdWorkflowinfo").datagrid('loadData', { rows: res.DBTable });
            });
        },
        //绑定工序信息表
        bindStepInfo: function (row) {
            clearEasyuiDataGrid("gdSpecInfo");
            page.post(page.url, { action: "GetStepAmountIterationInfo", workflowAmountIterationInfoID: row.WORKFLOWAMOUNTITERATIONINFOID }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdSpecInfo").datagrid('loadData', { rows: res.DBTable });
            });
        },
        //打开弹窗（添加、编辑功能）
        dialogs: function (rowData) {
            page.disableBtn(); //禁用主页面所有按钮
            dialogPage.init(rowData);
        },
        //删除
        deleData: function () {
            page.disableBtn(); //禁用所有按钮
            page.clearPage(false, false, true);
            var selected = $("#gdWorkflowinfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("请选择数据", false);
                page.enableBtn(); //恢复所有按钮
                return false;
            }
            var datas = selected.map(function (item) {
                return {
                    workflowAmountIterationInfoID: item.WORKFLOWAMOUNTITERATIONINFOID
                }
            });
            var formData = {
                action: "DeleWorkflowAmountIterationInfo",
                workflowParam: JSON.stringify(datas)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                page.enableBtn(); //恢复所有按钮
                displayMessage(res.Message, res.Result);
            });
        },
        //提交审批
        sendAudit: function (type) {
            page.disableBtn(); //禁用所有按钮
            page.clearPage(false, false, true);
            var selected = $("#gdWorkflowinfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("请选择数据", false);
                page.enableBtn(); //恢复所有按钮
                return false;
            }
            var datas = selected.map(function (item) {
                return {
                    workflowAmountIterationInfoID: item.WORKFLOWAMOUNTITERATIONINFOID
                }
            });
            var formData = {
                action: "UpdateWorkflowAmountIterationStatus",
                workflowParam: JSON.stringify(datas),
                type: type
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                page.enableBtn(); //恢复所有按钮
                displayMessage(res.Message, res.Result);
            });
        },
        //清除页面（查询区域，列表区域，填写区域，是否清空消息）
        clearPage: function (query, list, msg) {
            if (query) {
                $("#productContent").productCombo("init"); //件号
                $("#workflowContent").workflowCombo("init"); //工艺
                //                $("#selFactory").combobox("select", 0); //分厂
                $("#selStatus").combobox("setValue", ""); //状态
            }
            if (list) {
                clearEasyuiDataGrid("gdWorkflowinfo");
                clearEasyuiDataGrid("gdSpecInfo");
            }
            if (msg) {
                clearMessage();
            }
        },
        //禁用按钮
        disableBtn: function () {
            $("#mainDiv").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //启用按钮
        enableBtn: function () {
            $("#mainDiv").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    };

    /*---------弹窗页面对象-------------*/
    var dialogPage = {
        workflowAmountIterationInfoID: "", //工艺期量迭代ID
        param: {}, //保存的参数
        init: function (rowData) {
            $("#dg").dialog({
                onClose: function () { //弹窗关闭事件
                    page.enableBtn();
                }
            });
            dialogPage.initData(rowData);
        },
        //初始化页面数据
        initData: function (rowData) {
            dialogPage.clearPage();
            if (rowData !== undefined) {
                dialogPage.workflowAmountIterationInfoID = rowData.WORKFLOWAMOUNTITERATIONINFOID;
                dialogPage.param.productID = rowData.PRODUCTID; //件号
                dialogPage.param.referworkflowID = rowData.REFERWORKFLOWID; //参考的工艺
                dialogPage.param.renewWorkflowID = rowData.RENEWWORKFLOWID; //更新的工艺
                dialogPage.param.startDate = rowData.STARTDATE; //日期范围的开始日期
                dialogPage.param.endDate = rowData.ENDDATE; //日期范围的结束日期
                $("#productContentDialog").productCombo("setCombo", { productName: rowData.PRODUCTNAME, productID: rowData.PRODUCTID });
                $("#workflowContentDialog").workflowCombo("setValue", rowData.REFERWORKFLOWID);
                $("#selRenewWorkflow").combobox("setValue", rowData.RENEWWORKFLOWID);
                $("#txtTotaltimelimit").textbox("setValue", rowData.TOTALTIMELIMIT);
                $("#txtMaintenanceTotalTime").textbox("setValue", rowData.MAINTENANCETOTALTIME);
                $("#txtStartDate").datebox("setValue", rowData.STARTDATE);
                $("#txtEndDate").datebox("setValue", rowData.ENDDATE);
                page.post(page.url, { action: "GetStepAmountIterationInfo", workflowAmountIterationInfoID: rowData.WORKFLOWAMOUNTITERATIONINFOID }, true, function (res) {
                    if (!res.Result) {
                        displayMessage(res.Message, res.Result);
                        return;
                    }
                    $("#gdEditStepInfo").datagrid('loadData', { rows: res.DBTable });
                });
            }
        },
        //绑定页面事件
        bind: function () {
            $("#txtTotaltimelimit").textbox({
                readonly: true
            });
            $("#txtMaintenanceTotalTime").textbox({
                readonly: true
            });
            //工序列表加载
            $("#gdEditStepInfo").datagrid({
                columns: [[
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'FACTORYNAME', title: '分厂', width: 100 },
                 { field: 'WORKCENTERNAME', title: '工区', width: 80 },
                 { field: 'TEAMNAME', title: '班组', width: 80 },
                 { field: 'SPECTYPE', title: '工序类型', width: 60 },
                 { field: 'NCNUMBERNAME', title: '是否数控序', width: 70 },
                 { field: 'PREPARECYCLE', title: '准备时间(!)', width: 80 },
                 { field: 'PREPARECYCLEEDIT', title: '准备时间(min)', width: 90, editor: "numberbox" },
                 { field: 'CLAMPINGCYCLE', title: '装夹时间(!)', width: 80 },
                 { field: 'MAKECYCLE', title: '加工时间(!)', width: 80 },
                 { field: 'MAKECYCLEEDIT', title: '加工时间(min)', width: 90, editor: "numberbox" },
                 { field: 'TRANSFERCYCLE', title: '运转时间(!)', width: 80 },
                 { field: 'TRANSFERCYCLEEDIT', title: '运转时间(min)', width: 90, editor: "numberbox" },
                 { field: 'SHIPCYCLE', title: '转工周期(!)', width: 80 },
                 { field: 'SHIPCYCLEEDIT', title: '转工周期(h)', width: 80, editor: "numberbox" },
                 { field: 'COMMICYCLE', title: '外委周期(!)', width: 80 },
                 { field: 'COMMICYCLEEDIT', title: '外委周期(d)', width: 80, editor: "numberbox" },
                 { field: 'MAKEEMPCOUNTS', title: '作业人数', width: 70 },
                 { field: 'CHARGINGQTY', title: '装炉量', width: 70 }
                ]],
                onDblClickCell: function (index, field, value) {
                    $(this).datagrid('beginEdit', index);
                    $(this).datagrid('checkRow', index);
                },
                onClickRow: function (index) {
                    $(this).datagrid('acceptChanges');
                }
            });
            //计算实时工时
            $("#btnRealTime").on("click", function () {
                dialogPage.getRealTimeData();
            });
            //保存
            $("#btnSave").on("click", function () {
                dialogPage.saveAmountIterationData();
            });
        },
        //绑定其他版本的工艺
        bindOtherRevWorkflow: function (workflowId) {
            page.post(page.url, { action: "GetOtherRevWorkflowInfo", workflowID: workflowId }, false, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                //绑定工作中心
                $("#selRenewWorkflow").combobox({
                    valueField: 'WORKFLOWID',
                    textField: 'WORKFLOWNAMEANDREV',
                    data: res.DBTable //下拉数据
                });
            });
        },
        //获取实时工时
        getRealTimeData: function () {
            dialogPage.disableBtn();
            clearEasyuiDataGrid("gdEditStepInfo");
            dialogPage.param.productID = $("#productContentDialog").productCombo("getValue"); //件号
            if (isNullOrWhiteSpaceStr(dialogPage.param.productID)) {
                displayMessage("未选择件号", false);
                dialogPage.enableBtn();
                return;
            }
            dialogPage.param.referworkflowID = $("#workflowContentDialog").workflowCombo("getValue"); //参考的工艺
            if (isNullOrWhiteSpaceStr(dialogPage.param.referworkflowID)) {
                displayMessage("未选择产参考工艺", false);
                dialogPage.enableBtn();
                return;
            }
            dialogPage.param.renewWorkflowID = $("#selRenewWorkflow").combobox("getValue"); //更新的工艺
            if (isNullOrWhiteSpaceStr(dialogPage.param.renewWorkflowID)) {
                displayMessage("未选择产更新工艺", false);
                dialogPage.enableBtn();
                return;
            }
            dialogPage.param.startDate = $("#txtStartDate").datebox("getValue"); //日期范围的开始日期
            if (isNullOrWhiteSpaceStr(dialogPage.param.startDate)) {
                displayMessage("未选择参考周期的开始日期", false);
                dialogPage.enableBtn();
                return;
            }
            dialogPage.param.endDate = $("#txtEndDate").datebox("getValue"); //日期范围的结束日期
            if (isNullOrWhiteSpaceStr(dialogPage.param.endDate)) {
                displayMessage("未选择参考周期的结束日期", false);
                dialogPage.enableBtn();
                return;
            }
            var formData = {
                action: "GetStepAmountIterationTimeData",
                params: JSON.stringify(dialogPage.param)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    $("#txtTotaltimelimit").textbox("setValue", res.ReturnData); //总工时上限
                    $("#gdEditStepInfo").datagrid('loadData', { rows: res.DBTable });
                }
                dialogPage.enableBtn();
                displayMessage(res.Message, res.Result);
            });
        },
        //保存期量数据
        saveAmountIterationData: function () {
            dialogPage.disableBtn();
            $("#gdEditStepInfo").datagrid('acceptChanges');
            var resData = dialogPage.isVaildData();
            if (!resData.result) {
                dialogPage.enableBtn();
                displayMessage(resData.msg, resData.result);
                return;
            }
            dialogPage.param.workflowAmountIterationInfoID = dialogPage.workflowAmountIterationInfoID;
            var formData = {
                action: "SaveWorkflowAmountIterationInfo",
                params: JSON.stringify(dialogPage.param),
                stepDatas: JSON.stringify(resData.datas)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    dialogPage.clearPage();
                }
                dialogPage.enableBtn();
                displayMessage(res.Message, res.Result);
            });
        },
        //保存前验证数据
        isVaildData: function () {
            var resData = { result: true, msg: "" };
            if (isNullOrWhiteSpaceStr(dialogPage.param.productID)) {
                resData.result = false; resData.msg = "请先计算实时工时";
                return resData;
            }
            if (isNullOrWhiteSpaceStr(dialogPage.param.referworkflowID)) {
                resData.result = false; resData.msg = "请先计算实时工时";
                return resData;
            }
            if (isNullOrWhiteSpaceStr(dialogPage.param.renewWorkflowID)) {
                resData.result = false; resData.msg = "请先计算实时工时";
                return resData;
            }
            if (isNullOrWhiteSpaceStr(dialogPage.param.startDate)) {
                resData.result = false; resData.msg = "请先计算实时工时";
                return resData;
            }
            if (isNullOrWhiteSpaceStr(dialogPage.param.endDate)) {
                resData.result = false; resData.msg = "请先计算实时工时";
                return resData;
            }
            var rows = $("#gdEditStepInfo").datagrid("getRows");
            if (rows.length === 0) {
                resData.result = false; resData.msg = "没有工序信息";
                return resData;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].PREPARECYCLEEDIT === "") {
                    rows[i].PREPARECYCLEEDIT = null;
                }
                if (rows[i].PREPARECYCLEEDIT !== null && Number(rows[i].PREPARECYCLEEDIT) > Number(rows[i].PREPARECYCLE)) {
                    resData.result = false; resData.msg = "可编辑准备时间数值过大，请重新填写";
                    break;
                }
                if (rows[i].MAKECYCLEEDIT === "") {
                    rows[i].MAKECYCLEEDIT = null;
                }
                if (rows[i].MAKECYCLEEDIT !== null && rows[i].MAKECYCLEEDIT > rows[i].MAKECYCLE) {
                    resData.result = false; resData.msg = "可编辑加工时间数值过大，请重新填写";
                    break;
                }
                if (rows[i].TRANSFERCYCLEEDIT === "") {
                    rows[i].TRANSFERCYCLEEDIT = null;
                }
                if (rows[i].TRANSFERCYCLEEDIT !== null && rows[i].TRANSFERCYCLEEDIT > rows[i].TRANSFERCYCLE) {
                    resData.result = false; resData.msg = "可编辑转运时间数值过大，请重新填写";
                    break;
                }
                if (rows[i].SHIPCYCLEEDIT === "") {
                    rows[i].SHIPCYCLEEDIT = null;
                }
                if (rows[i].SHIPCYCLEEDIT !== null && rows[i].SHIPCYCLEEDIT > rows[i].SHIPCYCLE) {
                    resData.result = false; resData.msg = "可编辑转工周期数值过大，请重新填写";
                    break;
                }
                if (rows[i].COMMICYCLEEDIT === "") {
                    rows[i].COMMICYCLEEDIT = null;
                }
                if (rows[i].COMMICYCLEEDIT !== null && rows[i].COMMICYCLEEDIT > rows[i].COMMICYCLE) {
                    resData.result = false; resData.msg = "可编辑外委周期数值过大，请重新填写";
                    break;
                }
            }
            resData.datas = rows;
            return resData;
        },
        //清除页面数据
        clearPage: function () {
            dialogPage.workflowAmountIterationInfoID = "";
            dialogPage.param = {};
            clearEasyuiDataGrid("gdEditStepInfo");
            $("#productContentDialog").productCombo("init"); //初始化件号下拉组件
            $("#workflowContentDialog").workflowCombo("init"); //初始化工艺下拉组件
            $("#selRenewWorkflow").combobox("clear");
            $("#selRenewWorkflow").combo("panel").empty();
            $("#txtTotaltimelimit").textbox("setValue", "");
            $("#txtMaintenanceTotalTime").textbox("setValue", "");
            $("#txtStartDate").datebox("clear");
            $("#txtEndDate").datebox("clear");
        },
        //禁用按钮
        disableBtn: function () {
            $("#dg").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //启用按钮
        enableBtn: function () {
            $("#dg").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        }
    };

    /*---------主页面的件号-工艺路线组件对象-----------
    （不能页面加载后绑定，不然无法生效）
    */
    var productLinkWorkflow = {
        init: function () {
            //绑定件号选择组件
            $("#productContent").productCombo({
                search: function () { //查询事件
                    page.clearPage(false, true, true);
                    $("#workflowContent").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                },
                cancel: function () { //件号取消点击事件
                    page.clearPage(false, true, true);
                    $("#workflowContent").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                },
                selected: function (val, text) {//件号下拉选择事件
                    page.clearPage(false, true, true);
                    $("#workflowContent").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                    $("#workflowContent").workflowCombo("setCombo", { productName: text }); //联动工艺下拉
                }
            });
            //绑定工艺选择组件
            $("#workflowContent").workflowCombo({
                cancel: function () {//工艺取消点击事件
                    page.clearPage(false, true, true);
                },
                selected: function (val, text) {//工艺下拉选择事件
                    //                page.search(val);
                }
            });
        }
    };
    productLinkWorkflow.init();

    /*---------弹窗的件号-工艺路线组件对象-------------
    （不能页面加载后绑定，不然无法生效）
    */
    var productLinkWorkflowDialog = {
        init: function () {
            //绑定件号选择组件
            $("#productContentDialog").productCombo({
                search: function () { //查询事件
                    page.clearPage(false, true, true);
                    $("#workflowContentDialog").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                },
                cancel: function () { //件号取消点击事件
                    page.clearPage(false, true, true);
                    $("#workflowContentDialog").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                },
                selected: function (val, text) {//件号下拉选择事件
                    page.clearPage(false, true, true);
                    $("#workflowContentDialog").workflowCombo("init"); //同时恢复初始化工艺下拉组件
                    $("#workflowContentDialog").workflowCombo("setCombo", { productName: text }); //联动工艺下拉
                }
            });
            //绑定工艺选择组件
            $("#workflowContentDialog").workflowCombo({
                cancel: function () {//工艺取消点击事件
                    clearEasyuiDataGrid("gdEditStepInfo");
                },
                selected: function (val, text) {//工艺下拉选择事件
                    dialogPage.bindOtherRevWorkflow(val);
                }
            });
        }
    };
    productLinkWorkflowDialog.init();

    $(function () {
        page.init();
    });
</script>
